#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch>'9'||ch<'0'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0'){
        x=(x<<1)+(x<<3)+ch-48;
        ch=getchar();
    }
    return x*f;
}
bool h[1000010];
int ans,a[200010],red,bl;
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T=read(),n,s;
    while(T--){
        n=read();ans=0;
        for(int i=1;i<=n;i++)a[i]=read();
        for(int i=0;i<(1<<n-1);i++){
            s=0;red=-1,bl=-1;
            for(int j=0;j<n;j++){
                if(i&(1<<j))s+=a[j+1]*(a[j+1]==red),red=a[j+1];
                else s+=a[j+1]*(a[j+1]==bl),bl=a[j+1];
            }
            ans=max(ans,s);
        }
        cout<<ans<<"\n";
    }
    return 0;
}
